package com.inforich.web.controller.appManage;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.Arrays;
import cn.hutool.core.bean.BeanUtil;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;
import com.inforich.common.annotation.Log;
import com.inforich.common.core.controller.BaseController;
import com.inforich.common.core.domain.AjaxResult;
import com.inforich.common.enums.BusinessType;
import com.inforich.appManage.domain.AppApply;
import com.inforich.appManage.service.IAppApplyService;
import com.inforich.common.utils.poi.ExcelUtil;

/**
 * 移动应用管理Controller
 *
 * @author hjm
 * @date 2022-10-27
 */
@RestController
@RequestMapping("/appManage/appApply")
public class AppApplyController extends BaseController {

  @Autowired
  private IAppApplyService appApplyService;

  /**
   * 查询移动应用管理列表
   */
  @PreAuthorize("@ss.hasPermi('appManage:appApply:list')")
  @GetMapping("/list")
  public Page<AppApply> list(Page<AppApply> page, AppApply appApply) {
    Map<String, Object> map = beanToMap(appApply);
    appApplyService.pageAppApply(page, map);
    return page;
  }


  /**
   * 导出移动应用管理列表
   */
  @PreAuthorize("@ss.hasPermi('appManage:appApply:export')")
  @Log(title = "移动应用管理", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  public void export(HttpServletResponse response, AppApply appApply) {
    Map<String, Object> map = beanToMap(appApply);
    List<AppApply> list = appApplyService.listAppApply(map);
    ExcelUtil<AppApply> util = new ExcelUtil<AppApply>(AppApply.class);
    util.exportExcel(response, list, "移动应用管理数据");
  }

  /**
   * 获取移动应用管理详细信息
   */
  @PreAuthorize("@ss.hasPermi('appManage:appApply:query')")
  @GetMapping(value = "/{id}")
  public AjaxResult getInfo(@PathVariable("id") String id) {
    return AjaxResult.success(appApplyService.getById(id));
  }

  /**
   * 新增移动应用管理
   */
  @PreAuthorize("@ss.hasPermi('appManage:appApply:add')")
  @Log(title = "移动应用管理", businessType = BusinessType.INSERT)
  @PostMapping
  public AjaxResult add(@Validated @RequestBody AppApply appApply) {
    return toAjax(appApplyService.save(appApply));
  }

  /**
   * 修改移动应用管理
   */
  @PreAuthorize("@ss.hasPermi('appManage:appApply:edit')")
  @Log(title = "移动应用管理", businessType = BusinessType.UPDATE)
  @PutMapping
  public AjaxResult edit(@Validated @RequestBody AppApply appApply) {
    return toAjax(appApplyService.updateById(appApply));
  }

  /**
   * 删除移动应用管理
   */
  @PreAuthorize("@ss.hasPermi('appManage:appApply:remove')")
  @Log(title = "移动应用管理", businessType = BusinessType.DELETE)
  @DeleteMapping("/{ids}")
  public AjaxResult remove(@PathVariable String[] ids) {
    return toAjax(appApplyService.removeByIds(Arrays.asList(ids)));
  }
}
